{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "120bd921",
   "metadata": {},
   "source": [
    "In this part of the tutorial, we will write our first Fortran program:\n",
    "the ubiquitous [\"Hello, World!\"](https://en.wikipedia.org/wiki/%22Hello,_World!%22_program) example.\n",
    "\n",
    "However, before we can write our program, we need to ensure that we have\n",
    "a Fortran compiler set up.\n",
    "\n",
    "{% include note.html content=\"Fortran is a *compiled language*, which means that, once written, the source code must be passed through a\n",
    "compiler to produce a machine executable that can be run.\" %}\n",
    "\n",
    "## Compiler setup\n",
    "\n",
    "In this tutorial, we'll work with the free and open source \n",
    "[GNU Fortran compiler (gfortran)](https://gcc.gnu.org/fortran/), \n",
    "which is part of the \n",
    "[GNU Compiler Collection (GCC)](https://gcc.gnu.org/).\n",
    "\n",
    "To install gfortran on Linux, use your system package manager.\n",
    "On macOS, you can install gfortran using [Homebrew](https://brew.sh/) or [MacPorts](https://www.macports.org/).\n",
    "On Windows, you can get native binaries [here](http://www.equation.com/servlet/equation.cmd?fa=fortran).\n",
    "\n",
    "To check if you have _gfortran_ setup correctly, open a terminal and run the following command:\n",
    "\n",
    "```shell\n",
    "$> gfortran --version\n",
    "```\n",
    "\n",
    "this should output something like:\n",
    "\n",
    "```\n",
    "GNU Fortran 7.5.0\n",
    "Copyright (C) 2017 Free Software Foundation, Inc.\n",
    "This is free software; see the source for copying conditions.  There is NO\n",
    "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
    "```\n",
    "\n",
    "## Hello world\n",
    "\n",
    "Once you have set up your compiler, open a new file in your favourite code editor and enter the following:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b86b1c01",
   "metadata": {},
   "outputs": [],
   "source": [
    "program hello\n",
    "  ! This is a comment line; it is ignored by the compiler\n",
    "  print *, 'Hello, World!'\n",
    "end program hello"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "931034bb",
   "metadata": {},
   "source": [
    "Having saved your program to `hello.f90`, compile at the command line with:\n",
    "```shell\n",
    "$> gfortran hello.f90 -o hello\n",
    "```\n",
    "\n",
    "{% include note.html content=\"`.f90` is the standard file extension for modern Fortran source files.\n",
    "The 90 refers to the first modern Fortran standard in 1990.\" %}\n",
    "\n",
    "To run your compiled program:\n",
    "```shell\n",
    "$> ./hello\n",
    "Hello, World!\n",
    "```\n",
    "\n",
    "Congratulations, you've written, compiled and run your first Fortran program!\n",
    "In the next part of this tutorial, we will introduce variables for storing data."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Fortran",
   "language": "fortran",
   "name": "fortran"
  },
  "language_info": {
   "file_extension": ".f90",
   "mimetype": "text/x-fortran",
   "name": "fortran",
   "version": "2018"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
